# coding: utf-8
# Project：PyCharmMiscProject
# File：类和对象作业测试版.py
# Author：liuchuanzhi
# Date ：2025/4/9 20:28
# IDE：PyCharm
import random

# 定义超级英雄类
class SuperHero:
    def __init__(self, name, power, health):
        self.name = name
        self.power = power
        self.health = health

    def attack(self, other_hero):
        damage = random.randint(1, self.power)
        other_hero.health -= damage
        print(f"{self.name} 攻击了 {other_hero.name}，造成了 {damage} 点伤害！")
        if other_hero.health <= 0:
            print(f"{other_hero.name} 被击败了！")
        else:
            print(f"{other_hero.name} 还剩下 {other_hero.health} 点生命值。")

# 创建超级英雄对象
superman = SuperHero("超人", 50, 200)
batman = SuperHero("蝙蝠侠", 30, 150)

# 模拟战斗
print("战斗开始！")
while superman.health > 0 and batman.health > 0:
    if random.choice([True, False]):
        superman.attack(batman)
    else:
        batman.attack(superman)